export default {
  data() {
    return {

      form: {
        'invoice_kind': 0, //发票类型 0：个人/非事业单位 1：企业
        'person_title': '', //抬头名称
        'invoice_type': 2, //发票种类 2：增值税专票 3：增值税普票
        'company_title': '', //公司抬头
        'tax_number': '', //公司税号
        'bank_address': '', //企业开户行
        'card_numbers': '', //银行卡号
        'registered_telephone': '', //注册电话
        'registered_address': '' //注册地址
      },
      typeActive: 2,
      radioList: [{
        name: '单位',
        val: 1,
        disabled: false
      },
      {
        name: '个人/非企事业单位',
        val: 0,
        disabled: false
      }
      ],
      radio: 0,
      switchVal: false,
      orderMsg: [],
      money: 0
    }
  },
  onLoad(options) {
    let data = JSON.parse(decodeURIComponent(options.id))
    console.log(data)
    if (data) {
      this.form = data.tt
      this.orderMsg = data.order
      if (this.form.invoice_kind === 0) {
        this.$set(this.radioList[0], 'disabled', true)
      } else {
        this.$set(this.radioList[1], 'disabled', true)
      }
      this.orderMsg.forEach(it => {

        this.money += it.invoice_amount
      })
    }
  },
  methods: {

    async submit() {

      try {
        let orderId = [],
          money = 0
        this.orderMsg.forEach(it => {
          orderId.push({
            orderid: it.orderid,
            order_type: 3
          })
          money += it.invoice_amount
        })
        let data = {
          'titleid': this.form.id, //发票抬头主键
          'orders': orderId,
          'invoice_amount': money
        }

        const res = await this.$api.common.Invoiced(data)
        console.log(res)
        uni.showToast({
          title: '申请成功',
        })
        setTimeout(() => {
          uni.navigateBack({
            delta: 2
          })
        }, 1500)

      } catch (e) {
        //TODO handle the exception
      }

    }
  }
}
